<template>
    <div class="student-index" style="background:#fff; overflow:hidden;">
        <el-row class="student-index-title">
            <el-col :span="24">实训案例</el-col>
            <el-col :span="24">Training Project</el-col>
        </el-row>
        <div class="search-box">
            <div class="search-item">
                <span class="search-title">专业: </span>
                <el-select
                    v-model="professionValue"
                    placeholder="全部"
                    value-key="value"
                    style="float:left;">
                    <el-option
                    v-for="item in professionStatus"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value">
                    </el-option>
                </el-select>
            </div>
            <div class="search-item">
                <span class="search-title">行业类别: </span>
                <el-select
                    v-model="industryValue"
                    placeholder="请选择行业"
                    value-key="value"
                    style="float:left;">
                    <el-option
                    v-for="item in industryStatus"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value">
                    </el-option>
                </el-select>
            </div>
            <div class="search-item">
                <span class="search-title">类型: </span>
                <el-select
                    v-model="typeValue"
                    placeholder="类型"
                    value-key="value"
                    style="float:left;">
                    <el-option
                    v-for="item in typeStatus"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value">
                    </el-option>
                </el-select>
            </div>
            <div class="search-item">
                <span class="search-title">案例名称: </span>
                <el-input v-model="caseName" placeholder="请输入关键字" style="float:left; width:auto;"></el-input>
            </div>
            <div class="search-item">
                <el-button type="primary" @click="searchFn">搜索</el-button>
            </div>
        </div>
        <div class="student-index-list" v-if="listData.length > 0">
            <el-row :gutter="30">
                <el-col :span="6" v-for="(item, index) in listData" :key="index">
                    <div class="list-item" @click="storageProjectId(item.id, '/admin/projectintroduction',item.showEndItemFlag, item.presetChapterId, item.name)">
                        <div class="list-header" :style="{ background: item.colour }">
                            <div class="list-img">
                                <img :src="item.picUrl" />
                            </div>
                            <div class="list-text1">{{ item.name }}</div>
                            <div class="list-text2">{{ item.userName }}</div>
                        </div>
                        <div class="list-content">
                            <p>{{ item.description }}</p>
                        </div>
                        <div class="list-content-knot" v-if="item.showEndItemFlag" @click="storageProjectId(item.id, '/teacher/projectintroduction',item.showEndItemFlag, item.name)">
                            <img src="./../../assets/images/knot_icon.png" />
                        </div>
                        <div class="list-tag" :style="{ background: item.colour }" :title="item.typeName">{{ item.typeName }}</div>
                    </div>
                </el-col>
            </el-row>
        </div>
        <div class="student-tips" v-else style="text-align:center; padding:5% 0 10%;">
            <img src="./../../assets/images/project_tips3.jpg" />
        </div>
    </div>
</template>

<script>
    import { mapState } from 'vuex'
    export default {
        data () {
            return {
                listData:[],
                industryStatus: [
                    {
                        value: '',
                        label: '全部'
                    }
                ],
                industryValue: '',
                typeStatus: [
                    {
                        value: 1,
                        label: '预置'
                    },
                    {
                        value: 2,
                        label: '非预置'
                    }
                ],

                // 新增
                professionValue: '',
                professionStatus: [
                    {
                        value: '',
                        label: '全部'
                    }
                ],
                typeValue: '',
                caseName: ''
            }
        },
        created () {
            this.initSelect()
            this.init()     //初始化
            this.listInit()
            localStorage.removeItem('teacher-project-id')
        },
        computed:{
			...mapState(['itemServiceValue', 'chapterType','itemServiceType', 'projectBreadCrumbBack'])
		},
        methods: {
            initSelect(){
                let self = this
                self.$http.get('/dataplatform/major/list').then(response => {
                    let res = response.data
                    if(res.code == '200'){
                        for (let i = 0; i < res.data.length; i++) {
                            let industryJson = {}
                            industryJson.value = res.data[i].id
                            industryJson.label = res.data[i].name
                            self.professionStatus.push(industryJson)
                        }
                    }else if(res.code == '401'){
                        self.$router.replace({
                            path:'/login'
                        })
                    }else{
                        self.$message.error(res.message)
                    }
                })
            },
            init() {
                let self = this
                self.$http.get('/dataplatform/common/systemConfig/list?searchConfigs=industryType').then(response => {
                    let res = response.data
                    if(res.code == '200'){
                        for (let i = 0; i < res.data.length; i++) {
                            let industryJson = {}
                            industryJson.value = res.data[i].id
                            industryJson.label = res.data[i].keyValue
                            self.industryStatus.push(industryJson)
                        }
                    }else if(res.code == '401'){
                        self.$router.replace({
                            path:'/login'
                        })
                    }else{
                        self.$message.error(res.message)
                    }
                })
            },
            listInit(){
                let self = this
                self.$http.get('/dataplatform/item/list?itemServiceType=3&systemConfigId='+self.industryValue+'&name='+self.caseName+'&presetStatus='+self.typeValue+'&majorId='+self.professionValue).then((response) => {
                    let res = response.data
                    if(res.code == '200'){
                        self.listData = res.data
                    }else if(res.code == '401'){
                        self.$router.replace({
                            path:'/login'
                        })
                    }else{
                        self.$message.error(res.message)
                    }
                })
            },
            //存储案例ID
            storageProjectId(id,path,showEndItemFlag, chapterId, name){
                let self = this
                if(showEndItemFlag){
                    self.$message({
                        message: '已结项',
                        type: 'warning'
                    })
                    return
                }
                let result = {
                    itemId: id,
                    type: 1
                }
                localStorage.setItem('teacher-project-id', JSON.stringify(result))

                self.$http.get('/dataplatform/item/menu?itemId='+id+'&itemServiceType=3').then(response => {
                    let res = response.data
                    if(res.code == '200'){
                        this.$store.commit('updateItemServiceValue', res.data)
                        this.$store.commit('updateChapterType', chapterId)
                        this.$store.commit('updateItemServiceType', 3)
                        this.$store.commit('updateProjectBreadCrumbBack', name)
                        self.$router.push({
                            path: path
                        })
                    }else if(res.code == '401'){
                        self.$router.replace({
                            path:'/login'
                        })
                    }else{
                        self.$message.error(res.message)
                    }
                })
            },
            //跳转step获取章节ID
            goStep(id, path, type,showEndItemFlag){
                let self = this
                if(showEndItemFlag){
                    self.$message({
                        message: '已结项',
                        type: 'warning'
                    })
                    return
                }
                //type==1预置2自定义
                let result = {
                    itemId: id,
                    type: type
                }
                localStorage.setItem('teacher-project-id', JSON.stringify(result))
                self.$http.get('/dataplatform/chapter/getChapterId?itemId='+id+'&chapterType='+type).then(response => {
                    let res = response.data
                    if(res.code == '200'){
                        this.$store.commit('updateChapterType', res.data)
                        this.$store.commit('updateItemServiceType', 1)
                        self.$router.push({
                            path: path
                        })
                    }else if(res.code == '401'){
                        self.$router.replace({
                            path:'/login'
                        })
                    }else{
                        self.$message.error(res.message)
                    }
                })
            },
            searchFn(){
                this.listInit()
            }
        }
    }
</script>

<style lang="scss">
    @import '@/assets/styles/student.scss';
</style>


